﻿namespace Basic.Cluster.Manager
{
    public class ClusterConfig
    {
        public string ClusterManagerProxy { get; set; } = "Consul";

        public string ClusterManagerAddress { get; set; }

        public int? HealthInterval { get; set; } = 15;

        public int? HealthTimeout { get; set; } = 5;

        #region 

        /// <summary>
        /// 服务注册表
        /// </summary>
        public IDictionary<string, string> ServiceMeta { get; set; }

        public string this[string key]
        {
            get => ServiceMeta == null ? null : ServiceMeta[key];
            set => (ServiceMeta ??= new Dictionary<string, string>())[key] = value;
        }

        public string ID => $"{Name}-{IP}-{Port}";

        public string Name => this["Name"];

        public string IP => this["IP"];

        public int Port => int.TryParse(this["Port"], out int port) ? port : 0;

        public string HealthCheck => this["HealthCheck"];

        #endregion

    }
}